package com.luo.chengrui.module.sa.dal.mysql.datapermission;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.luo.chengrui.module.sa.dal.dataobject.datapermission.DataPermissionItemDO;
import org.apache.ibatis.annotations.Mapper;
import com.luo.chengrui.module.sa.controller.admin.datapermission.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 数据权限项，每一项对应一个业务权限场景 Mapper
 *
 * @author 诚睿
 */
@Mapper
public interface DataPermissionItemMapper extends BaseMapperX<DataPermissionItemDO> {

    default PageResult<DataPermissionItemDO> selectPage(DataPermissionItemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DataPermissionItemDO>()
                .eqIfPresent(DataPermissionItemDO::getFolderId, reqVO.getFolderId())
                .likeIfPresent(DataPermissionItemDO::getFolderName, reqVO.getFolderName())
                .eqIfPresent(DataPermissionItemDO::getDefineId, reqVO.getDefineId())
                .likeIfPresent(DataPermissionItemDO::getCode, reqVO.getCode())
                .likeIfPresent(DataPermissionItemDO::getName, reqVO.getName())
                .eqIfPresent(DataPermissionItemDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DataPermissionItemDO::getRemark, reqVO.getRemark())
                .eqIfPresent(DataPermissionItemDO::getVersion, reqVO.getVersion())
                .orderByDesc(DataPermissionItemDO::getVersion));
    }

    default List<DataPermissionItemDO> selectList(DataPermissionItemExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DataPermissionItemDO>()
                .eqIfPresent(DataPermissionItemDO::getFolderId, reqVO.getFolderId())
                .likeIfPresent(DataPermissionItemDO::getFolderName, reqVO.getFolderName())
                .eqIfPresent(DataPermissionItemDO::getDefineId, reqVO.getDefineId())
                .likeIfPresent(DataPermissionItemDO::getCode, reqVO.getCode())
                .likeIfPresent(DataPermissionItemDO::getName, reqVO.getName())
                .eqIfPresent(DataPermissionItemDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DataPermissionItemDO::getRemark, reqVO.getRemark())
                .eqIfPresent(DataPermissionItemDO::getVersion, reqVO.getVersion())
                .orderByDesc(DataPermissionItemDO::getVersion));
    }

    DataPermissionItemDO selectBySubCode(@Param("params")DataPermissionItemDO item);
}
